﻿using PLC.Core.Entities;
using PLC.Interface.Recipes;
using System.Threading.Tasks;
using YWM.Application;
using YWM.Dto;

namespace PLC.Application.Recipes.Services
{
    internal class RecipeService : AsyncCrudService<Recipe, RecipeResultDto, long, PagedAndSortedResultRequestDto, RecipeDto>, IRecipeService
    {
        public async Task Apply(RecipeDto input)
        {
            Recipe recipe = await Repository.FirstOrDefaultAsync(r => r.IsDefault);
            if (recipe != null)
            {
                recipe.IsDefault = false;
                await Repository.UpdateAsync(recipe);
            }
            await Update(input);
        }
    }
}
